home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / c / tagsgen.exe / CTAG.E < prev    next >
Text File  |  1992-03-29  |  73KB  |  2,137 lines

  1. /*
  2.  EPSHeader
  3.  
  4.    File: ctag.c
  5.    Author: J. Kercheval
  6.    Created: Sun, 07/14/1991  17:24:44
  7. */
  8. /*
  9.  EPSRevision History
  10.  
  11.    J. Kercheval  Sat, 07/27/1991  22:08:04  creation
  12.    J. Kercheval  Sun, 08/18/1991  20:58:13  completion of C_get_token()
  13.    J. Kercheval  Wed, 08/21/1991  22:34:49  place function recognition
  14.    J. Kercheval  Wed, 08/21/1991  23:11:17  add defines and macros
  15.    J. Kercheval  Wed, 08/21/1991  23:54:33  add typedef and class parsing
  16.    J. Kercheval  Thu, 08/22/1991  23:53:51  add global variables
  17.    J. Kercheval  Thu, 08/22/1991  23:54:05  add enum, struct, union
  18.    J. Kercheval  Thu, 08/22/1991  23:54:28  add globals via typedefs
  19.    J. Kercheval  Sun, 08/25/1991  23:09:28  complete semantic parser
  20.    J. Kercheval  Tue, 08/27/1991  23:28:34  fix bug in typedef, struct, enum and union declarations
  21.    J. Kercheval  Sat, 08/31/1991  23:58:03  add prototype parsing
  22.    J. Kercheval  Tue, 09/03/1991  22:28:55  move many macros to functions
  23.    J. Kercheval  Tue, 09/03/1991  23:05:34  clean code and consolidate to functions
  24.    J. Kercheval  Sun, 09/08/1991  13:24:53  minor bug fix in function and global variable parser
  25.    J. Kercheval  Sun, 09/08/1991  21:31:06  fix bug in lexical parser
  26.    J. Kercheval  Sun, 09/08/1991  23:44:46  \v is not a valid literal in Epsilon, remove it
  27.    J. Kercheval  Mon, 09/09/1991  21:49:00  fix bug in function parser
  28.    J. Kercheval  Mon, 09/09/1991  22:44:46  fix bug in define parser
  29.    J. Kercheval  Tue, 09/10/1991  22:06:09  fix typedef parser
  30.    J. Kercheval  Wed, 09/11/1991  02:04:48  add extern symbol recognition
  31.    J. Kercheval  Wed, 09/11/1991  19:49:11  fix bug in function pointer variable declaration
  32.    J. Kercheval  Wed, 09/11/1991  20:38:13  add support for function pointer variable declarations after first declaration
  33.    J. Kercheval  Wed, 09/11/1991  21:51:37  move #directive parsing between semantic and lexical parser
  34.    J. Kercheval  Thu, 09/12/1991  22:44:43  add support for #ifdef blocks to avoid unmatched parens in ToLevelZero parsing
  35.    J. Kercheval  Fri, 09/13/1991  01:17:05  add when_loading() to remap def_srch_case_map[]
  36.    J. Kercheval  Wed, 09/18/1991  22:05:02  fix bug in GetToken and DiscardLine
  37.    J. Kercheval  Thu, 09/19/1991  22:26:09  fix bug in lexical parser when parsing non C syntax files
  38.    J. Kercheval  Thu, 10/03/1991  12:47:53  add .cc and .cpp extensions
  39.    J. Kercheval  Thu, 10/03/1991  18:15:10  add support for Static declarations
  40.    J. Kercheval  Fri, 10/04/1991  11:13:23  add support for tagging enumeration constants
  41.    J. Kercheval  Mon, 10/07/1991  09:36:07  create CParseEnumerationConstants()
  42.    J. Kercheval  Tue, 11/12/1991  22:46:16  add junk filter for tag output
  43.    J. Kercheval  Sat, 03/28/1992  13:50:06  fix a few bugs and add extern "C" parsing
  44. */
  45.  
  46. /*
  47.  * This file implements tagging for .C, .H and .E files which contain
  48.  * standard C and C++ syntax.  This file defines no new commands and is
  49.  * intended to work with the tags package included with V5.0 of Epsilon.
  50.  * There is no problem using modified tags packages providing calls are made
  51.  * to tags_suffix_???() routines in the same way Epsilon does this and that
  52.  * an output routine add_tag() is used.  All that should be required is to
  53.  * compile and load this file and this module will be used transparently to
  54.  * you.  If you wish to costumize the types of tags output modify the global
  55.  * variables CTagWant?????? which when TRUE allow the output of that type of
  56.  * tag and when FALSE prohibit that type of tag.
  57.  *
  58.  * This module implements tagging for union, struct, enum, typedef, #define,
  59.  * global variables, classes, prototypes and functions (all of which may be
  60.  * specifically turned on and off.  The performance cost for this level of
  61.  * accuracyis not trivial.  This parser knows a lot about the syntax of C and
  62.  * takes a fair amount of time.  You should expect to see a file complete
  63.  * somewhere in the range of 125%-150% of the time as Lugaru's tagger for C.
  64.  * This is not only because of the detail of the tags but also the larger
  65.  * number of them.  This tagger is not intended to do all of your work for
  66.  * you but is designed to be used in conjunction with the tags generator I
  67.  * have developed and is now available.  This file implements the same
  68.  * lexical and semantic parser as is found in that executable.  Use the
  69.  * executable in your make file for very fast and updated tags.  If you have
  70.  * problems finding it, contact me and I can point the way...
  71.  *
  72.  * There is defined at the end of this module a when_loading() function which
  73.  * alters the default search case map to allow *correct* (or at least
  74.  * consistent sorting with sort routines external to Epsilon.  In particular,
  75.  * to produce the same sort order as any UNIX, VMS or HP style sort or with
  76.  * the tags generator this module is supposed to coexist with this mapping
  77.  * must be done.  You should see no difference in the location of sorted
  78.  * buffers except for lines starting with ^, [, \, ] and _.
  79.  *
  80.  * This code is dedicated to the public domain with the caveat that Lugaru is
  81.  * welcome to use this within their distribution source code which is
  82.  * supplied with Epsilon.
  83.  *
  84.  * Good Tagging,
  85.  *
  86.  *      jbk@wrq.com
  87.  *
  88.  *      John Kercheval
  89.  *      127 NW Bowdoin Pl #105
  90.  *      Seattle, WA  98107-4960
  91.  *      September 8, 1991
  92.  */
  93.  
  94. #include <eel.h>
  95.  
  96. #define BOOLEAN int
  97. #define TRUE 1
  98. #define FALSE 0
  99.  
  100. #define CBUFSIZE 4096
  101. #define MAX_TOKEN_LENGTH 4096
  102.  
  103.  
  104. /* the following variable determine the behavior of the parser with respect
  105.  * to the token types which are output as a tag.  Note that use of the
  106.  * CTagWantExtern variable is a modifier and will only be effective when
  107.  * other options are used (ie. CTagWantProtoType must be specified to obtain
  108.  * extern prototypes, CTagWantExtern alone yields nothing).  Note also that
  109.  * the CTagWantExtern modifier has no effect for function, define and macro
  110.  * tags which are tagged only according only to the CTagWantFunction,
  111.  * CTagWantDefine and CTagWantMacro variables respectively.  CTagWantStatic
  112.  * is also a modifier and will allow tags of internal statically defined
  113.  * variables and other declarations.  CTagWantStatic also has no effect on
  114.  * Define and Macro tags.
  115.  */
  116. BOOLEAN CTagWantFunction = TRUE;
  117. BOOLEAN CTagWantProtoType = FALSE;
  118. BOOLEAN CTagWantStructure = TRUE;
  119. BOOLEAN CTagWantTypeDefinition = TRUE;
  120. BOOLEAN CTagWantMacro = TRUE;
  121. BOOLEAN CTagWantEnumeration = TRUE;
  122. BOOLEAN CTagWantEnumerationConstant = TRUE;
  123. BOOLEAN CTagWantUnion = TRUE;
  124. BOOLEAN CTagWantGlobalVariable = TRUE;
  125. BOOLEAN CTagWantClass = TRUE;
  126. BOOLEAN CTagWantDefine = TRUE;
  127. BOOLEAN CTagWantExtern = FALSE;
  128. BOOLEAN CTagWantStatic = TRUE;
  129.  
  130.  
  131. /* function for determining if character is whitespace */
  132. #define IsWhite(c) ( _C_white_table[c] )
  133.  
  134. /* the indexed table for white space character lookup */
  135. BOOLEAN _C_white_table[256];
  136.  
  137. /* list of whitespace characters */
  138. char C_white[] = " \f\t\n\r";
  139.  
  140.  
  141. /* function for determining if character is a delimiter */
  142. #define IsDelim(c) ( _C_delim_table[c] )
  143.  
  144. /* the indexed table for token delimiter lookup */
  145. BOOLEAN _C_delim_table[256];
  146.  
  147. /* list of token delimiters */
  148. char C_delim[] = " \f\t\n\r\"[](){}#;:,.'=-+*/%&|^~!<>?";
  149.  
  150.  
  151. /* function for determining if character is a puncuator */
  152. #define IsPunctuator(c) ( _C_punctuator_table[c] )
  153.  
  154. /* the indexed table for punctuator character lookup */
  155. BOOLEAN _C_punctuator_table[256];
  156.  
  157. /* list of punctuators */
  158. char C_punctuator[] = "[](){},;=";
  159.  
  160.  
  161. char C_open_brace[] = "{[(";    /* open brace set */
  162. char C_close_brace[] = ")]}";   /* close brace set */
  163.  
  164.  
  165. /*
  166.  * These defines are used to denote the type of the current tag
  167.  */
  168. #define NOP 0
  169. #define Function 1
  170. #define ProtoType 2
  171. #define Structure 3
  172. #define TypeDefinition 4
  173. #define Macro 5
  174. #define Enumeration 6
  175. #define EnumerationConstant 7
  176. #define Union 8
  177. #define GlobalVariable 9
  178. #define Class 10
  179. #define Define 11
  180. #define Extern 12
  181. #define Static 13
  182.  
  183. /* convenient definition */
  184. typedef int SymbolType;
  185.  
  186.  
  187. /* the current file buffer state */
  188. typedef struct BufferStruct {
  189.     int token_line_location;    /* current token line in buffer */
  190.     char *inbuf;                /* the buffer currently being parsed */
  191. } Buffer;
  192.  
  193.  
  194. /* the current input token state */
  195. typedef struct TokenStruct {
  196.     char sbuf1[MAX_TOKEN_LENGTH];       /* the first token buffer */
  197.     int charloc1;               /* the char location of sbuf1 */
  198.     int tokenline1;             /* the line number of sbuf1 */
  199.  
  200.     char sbuf2[MAX_TOKEN_LENGTH];       /* the second token buffer */
  201.     int charloc2;               /* the char location of sbuf2 */
  202.     int tokenline2;             /* the line number of sbuf2 */
  203.  
  204.     char *cur_token;            /* pointer to the current token buffer */
  205.     int *cur_char_location;     /* the location of current token */
  206.     int *cur_token_line;        /* the line of the current token */
  207.  
  208.     char *prev_token;           /* pointer to the last token buffer */
  209.     int *prev_char_location;    /* the location of previous token */
  210.     int *prev_token_line;       /* the line of the previous token */
  211.  
  212.     int token_count;            /* temporary variable, used by ToPunctuator */
  213.     int else_nesting_level;     /* the current nesting level */
  214.  
  215.     BOOLEAN extern_active;      /* minor state for this statement */
  216.     BOOLEAN CPP_extern_active;  /* minor state for this statement */
  217.     BOOLEAN static_active;      /* minor state for this statement */
  218. } Token;
  219.  
  220.  
  221. #define SYMBOL_SIZE 20
  222.  
  223. /* a list of known C tokens and keywords */
  224. char C_token_list[][SYMBOL_SIZE] =
  225. {
  226.     "*ivclsdfuaretp_hn\"",      /* list of starting characters of symbols
  227.                                  * below */
  228.     "*",                        /* pointer */
  229.     "\"C\"",                    /* C++ extern for C code */
  230.     "int",                      /* integer declaration */
  231.     "void",                     /* void type */
  232.     "char",                     /* character */
  233.     "long",                     /* long integer */
  234.     "short",                    /* short integer */
  235.     "double",                   /* double floating point */
  236.     "float",                    /* floating point */
  237.     "signed",                   /* signed integer */
  238.     "unsigned",                 /* unsigned integer */
  239.     "auto",                     /* auto variable (local duration) */
  240.     "register",                 /* register variable */
  241.     "static",                   /* static variable */
  242.     "struct",                   /* structure define */
  243.     "union",                    /* union define */
  244.     "enum",                     /* enum defined */
  245.     "typedef",                  /* type definition */
  246.     "const",                    /* constant variable */
  247.     "extern",                   /* external declaration */
  248.     "class",                    /* class declaration */
  249.     "friend",                   /* class modifier */
  250.     "private",                  /* class modifier */
  251.     "protected",                /* class modifier */
  252.     "public",                   /* class modifier */
  253.     "volatile",                 /* Compiler warning */
  254.     "_based",                   /* pointer type */
  255.     "_cdecl",                   /* parameter calling sequence, C style */
  256.     "cdecl",                    /* parameter calling sequence, C style */
  257.     "_far",                     /* pointer type */
  258.     "far",                      /* pointer type */
  259.     "_huge",                    /* pointer type */
  260.     "huge",                     /* pointer type */
  261.     "_near",                    /* pointer type */
  262.     "near",                     /* pointer type */
  263.     "_pascal",                  /* parameter calling sequence, PASCAL style */
  264.     "pascal",                   /* parameter calling sequence, PASCAL style */
  265.     "_fortran",                 /* parameter calling sequence, FORTRAN style */
  266.     "_fastcall",                /* parameter calling sequence, via registers */
  267.     "\0"
  268. };
  269.  
  270.  
  271. /*----------------------------------------------------------------------------
  272.  *
  273.  * CParserInit() initializes the tables required by the parser. The tables
  274.  * used are a simple boolean index which are true if the character
  275.  * corresponding to the index is a member of the associated table.
  276.  *
  277.  ---------------------------------------------------------------------------*/
  278.  
  279. CParserInit()
  280. {
  281.     char *s;
  282.     int i;
  283.  
  284.     /* init the entire block to FALSE */
  285.     for (i = 0; i < 256; i++) {
  286.         _C_delim_table[i] = FALSE;
  287.         _C_white_table[i] = FALSE;
  288.         _C_punctuator_table[i] = FALSE;
  289.     }
  290.  
  291.     /* set the characters in the delim set to TRUE */
  292.     for (s = C_delim; *s; s++) {
  293.         _C_delim_table[*s] = TRUE;
  294.     }
  295.  
  296.     /* set the characters in the white set to TRUE */
  297.     for (s = C_white; *s; s++) {
  298.         _C_white_table[*s] = TRUE;
  299.     }
  300.  
  301.     /* set the characters in the punctuator set to TRUE */
  302.     for (s = C_punctuator; *s; s++) {
  303.         _C_punctuator_table[*s] = TRUE;
  304.     }
  305. }
  306.  
  307.  
  308. /*----------------------------------------------------------------------------
  309.  *
  310.  * strchr() is the standard string library function strchr()
  311.  *
  312.  ---------------------------------------------------------------------------*/
  313.  
  314. char *strchr(s, c)
  315.     char *s;
  316.     char c;
  317. {
  318.     char *ret = s;
  319.  
  320.     while (*ret) {
  321.         if (*ret == c)
  322.             return ret;
  323.         ret++;
  324.     }
  325.  
  326.     if (*ret == c)
  327.         return ret;
  328.  
  329.     return NULL;
  330. }
  331.  
  332.  
  333. /*----------------------------------------------------------------------------
  334.  *
  335.  * CSymbolWanted() returns true if flags are true for the symbol type passed
  336.  * and false otherwise.
  337.  *
  338.  ---------------------------------------------------------------------------*/
  339.  
  340. BOOLEAN CSymbolWanted(type)
  341.     SymbolType type;
  342. {
  343.     switch (type) {
  344.         case Function:
  345.             return CTagWantFunction;
  346.             break;
  347.         case ProtoType:
  348.             return CTagWantProtoType;
  349.             break;
  350.         case GlobalVariable:
  351.             return CTagWantGlobalVariable;
  352.             break;
  353.         case Define:
  354.             return CTagWantDefine;
  355.             break;
  356.         case Macro:
  357.             return CTagWantMacro;
  358.             break;
  359.         case Structure:
  360.             return CTagWantStructure;
  361.             break;
  362.         case TypeDefinition:
  363.             return CTagWantTypeDefinition;
  364.             break;
  365.         case Enumeration:
  366.             return CTagWantEnumeration;
  367.             break;
  368.         case EnumerationConstant:
  369.             return CTagWantEnumerationConstant;
  370.             break;
  371.         case Union:
  372.             return CTagWantUnion;
  373.             break;
  374.         case Class:
  375.             return CTagWantClass;
  376.             break;
  377.         default:
  378.             return FALSE;
  379.             break;
  380.     }
  381. }
  382.  
  383.  
  384. /*----------------------------------------------------------------------------
  385.  *
  386.  * CTokenType() takes the token passed and determines if the token is a
  387.  * special token.  Special tokens require specialized handling in the parser.
  388.  * The function returns the type of token according to the SymbolTypeEnum
  389.  * enumeration.  This routine can only tell so much from one symbol but will
  390.  * return some type for all the *interesting* tokens.  Anything that is
  391.  * loosely defined is given back with the closest type available and the
  392.  * parser must give it contextual meaning
  393.  *
  394.  ---------------------------------------------------------------------------*/
  395.  
  396. SymbolType CTokenType(token)
  397.     char *token;
  398. {
  399.     /* look for dirty rejection */
  400.     if (!strchr("cestu#", token[0]))
  401.         return NOP;
  402.  
  403.     /* macro and non macro defines */
  404.     if (!strcmp(token, "#"))
  405.         return Define;
  406.  
  407.     /* structure declarations */
  408.     if (!strcmp(token, "struct"))
  409.         return Structure;
  410.  
  411.     /* type declaration */
  412.     if (!strcmp(token, "typedef"))
  413.         return TypeDefinition;
  414.  
  415.     /* enumeration declaration */
  416.     if (!strcmp(token, "enum"))
  417.         return Enumeration;
  418.  
  419.     /* union declaration */
  420.     if (!strcmp(token, "union"))
  421.         return Union;
  422.  
  423.     /* class declaration */
  424.     if (!strcmp(token, "class"))
  425.         return Class;
  426.  
  427.     /* external declaration */
  428.     if (!strcmp(token, "extern"))
  429.         return Extern;
  430.  
  431.     /* static declaration */
  432.     if (!strcmp(token, "static"))
  433.         return Static;
  434.  
  435.     /* do not recognize it as anything special */
  436.     return NOP;
  437. }
  438.  
  439.  
  440. /*----------------------------------------------------------------------------
  441.  *
  442.  * CIsDeclarationToken() takes the token passed and determines if the token
  443.  * is a declaration keyword used in C.  The user may define new declaration
  444.  * keywords via use of the typedef keyword.  This alters the syntax of C.  If
  445.  * the syntax is changed in this way it is probable that this routine would
  446.  * not return the correct value.  For the standard uses of this routine that
  447.  * information should not hinder performance for the vast majority of the
  448.  * cases.
  449.  *
  450.  ---------------------------------------------------------------------------*/
  451.  
  452. BOOLEAN CIsDeclarationToken(token)
  453.     char *token;
  454. {
  455.     int index;
  456.  
  457.     /* look for dirty rejection */
  458.     if (!strchr(C_token_list[0], token[0]))
  459.         return FALSE;
  460.  
  461.     /* march through array until membership is determined */
  462.     for (index = 1; *C_token_list[index]; (index)++) {
  463.  
  464.         /* return true if token found */
  465.         if (!strcmp(token, C_token_list[index])) {
  466.             return TRUE;
  467.         }
  468.     }
  469.  
  470.     /* did not find it */
  471.     return FALSE;
  472. }
  473.  
  474.  
  475. /*----------------------------------------------------------------------------
  476.  *
  477.  * COutputToken() will output a token of a given type.  The token is output
  478.  * if the passed token type is requested from the command line.
  479.  *
  480.  ---------------------------------------------------------------------------*/
  481.  
  482. COutputToken(token, token_buffer, token_type, infname, outbuf)
  483.     Token *token;
  484.     Buffer *token_buffer;
  485.     SymbolType token_type;
  486.     char *infname;
  487.     char *outbuf;
  488. {
  489.     /* filter junk symbols */
  490.     if (!IsDelim(token->prev_token[0])) {
  491.  
  492.         /* check that the symbol is wanted and output it if so */
  493.         if (CSymbolWanted(token_type)) {
  494.  
  495.             if (token->extern_active) {
  496.                 if (!CTagWantExtern) {
  497.                     if (token_type != Function &&
  498.                         token_type != Define &&
  499.                         token_type != Macro) {
  500.                         return;
  501.                     }
  502.                 }
  503.             }
  504.             /* return if statics are not wanted */
  505.             if (token->static_active) {
  506.                 if (!CTagWantStatic) {
  507.                     if (token_type != Define &&
  508.                         token_type != Macro) {
  509.                         return;
  510.                     }
  511.                 }
  512.             }
  513.             add_tag(token->prev_token,
  514.                     *(token->prev_char_location) -
  515.                     strlen(token->prev_token));
  516.         }
  517.     }
  518. }
  519.  
  520.  
  521. /*----------------------------------------------------------------------------
  522.  *
  523.  * CGetToken() will obtain the next token in the line pointed to by lptr and
  524.  * in addition will return FALSE if EOL is reached.  This routine is passed
  525.  * an inbut buffer (Cbuf) and a current pointer into the buffer.  It is the
  526.  * responsibility of this routine to refill the buffer if required.  Quoted
  527.  * strings and single quoted characters are returned as a single token.
  528.  * Comments are completely ignored by this parser.  The token will not exceed
  529.  * max_token_length - 1 in length (not including the end of line delimiter)
  530.  *
  531.  ---------------------------------------------------------------------------*/
  532.  
  533. BOOLEAN CGetToken(inbuf, token, max_token_length, line_number)
  534.     char *inbuf;
  535.     char *token;
  536.     int max_token_length;
  537.     int *line_number;
  538. {
  539.     /* a state of the lexical parser */
  540. #define Parse 0
  541. #define BeginCommentMaybe 1
  542. #define InComment 2
  543. #define InCommentEndMaybe 3
  544. #define InCPPComment 4
  545. #define InQuoteNormal 5
  546. #define InQuoteLiteral 6
  547. #define InSingleQuoteNormal 7
  548. #define InSingleQuoteLiteral 8
  549. #define EndSingleQuote 9
  550. #define WhiteSpace 10
  551. #define Exit 11
  552.  
  553.     typedef int State;
  554.  
  555.     State current_state;        /* the current state of the parser */
  556.  
  557.     char c;                     /* the current character being examined */
  558.     char *t;                    /* pointer into token */
  559.  
  560.     int token_length;           /* the current token_length cannot exceed
  561.                                  * max token length */
  562.  
  563.     /* init */
  564.     current_state = WhiteSpace;
  565.     t = token;
  566.     *t = '\0';
  567.     token_length = 0;
  568.  
  569.     /* parse the file for the next token */
  570.     while (TRUE) {
  571.  
  572.         /* if the buffer has been completely used, return FALSE */
  573.         if (point == size())
  574.             return FALSE;
  575.  
  576.         c = curchar();
  577.         point++;
  578.  
  579.         /* react on the state machine */
  580.         switch (current_state) {
  581.  
  582.             case Parse:
  583.                 switch (c) {
  584.  
  585.                     case '/':
  586.  
  587.                         /* return if we already have a token */
  588.                         if (t != token) {
  589.                             point--;
  590.                             current_state = Exit;
  591.                         }
  592.                         else {
  593.                             /* this may be the begin if a comment or the
  594.                              * division symbol, read the next character after
  595.                              * verifying it the buffer doesn't need refilling */
  596.                             current_state = BeginCommentMaybe;
  597.                             *t = c;
  598.                         }
  599.                         break;
  600.  
  601.                     case '\"':
  602.  
  603.                         /* return if we already have a token */
  604.                         if (t != token) {
  605.                             point--;
  606.                             current_state = Exit;
  607.                         }
  608.                         else {
  609.                             current_state = InQuoteNormal;
  610.                             *t++ = c;
  611.                             token_length++;
  612.                         }
  613.                         break;
  614.  
  615.                     case '\'':
  616.  
  617.                         /* return if we already have a token */
  618.                         if (t != token) {
  619.                             point--;
  620.                             current_state = Exit;
  621.                         }
  622.                         else {
  623.                             current_state = InSingleQuoteNormal;
  624.                             *t++ = c;
  625.                             token_length++;
  626.                         }
  627.                         break;
  628.  
  629.                     default:
  630.  
  631.                         /* if it is a delimiter than stop processing */
  632.                         if (IsDelim(c)) {
  633.  
  634.                             /* if a token exists then back up in buffer */
  635.                             if (t != token) {
  636.                                 point--;
  637.                             }
  638.                             else {
  639.                                 *t++ = c;
  640.                                 token_length++;
  641.                             }
  642.                             current_state = Exit;
  643.                         }
  644.                         else {
  645.  
  646.                             /* normal character, store it in the token */
  647.                             *t++ = c;
  648.                             token_length++;
  649.                         }
  650.                         break;
  651.                 }
  652.                 break;
  653.  
  654.             case WhiteSpace:
  655.  
  656.                 /* pass over whitespace, backup one char if no longer in
  657.                  * white space region */
  658.                 if (!IsWhite(c)) {
  659.                     current_state = Parse;
  660.                     point--;
  661.                 }
  662.                 else {
  663.  
  664.                     /* check for newline */
  665.                     if (c == '\n') {
  666.                         (*line_number)++;
  667.                     }
  668.                 }
  669.                 break;
  670.  
  671.             case BeginCommentMaybe:
  672.                 switch (c) {
  673.  
  674.                     case '/':
  675.                         current_state = InCPPComment;
  676.                         break;
  677.  
  678.                     case '*':
  679.                         current_state = InComment;
  680.                         break;
  681.  
  682.                     default:
  683.                         t++;
  684.                         token_length++;
  685.                         point--;
  686.                         current_state = Exit;
  687.                         break;
  688.                 }
  689.                 break;
  690.  
  691.             case InComment:
  692.                 switch (c) {
  693.  
  694.                     case '*':
  695.                         /* this is potentially the end of the comment */
  696.                         current_state = InCommentEndMaybe;
  697.                         break;
  698.  
  699.                     case '\n':
  700.                         /* new line just increment state variables */
  701.                         (*line_number)++;
  702.                         break;
  703.  
  704.                     default:
  705.                         break;
  706.                 }
  707.                 break;
  708.  
  709.             case InCommentEndMaybe:
  710.                 switch (c) {
  711.  
  712.                     case '/':
  713.                         /* this is indeed the end of the comment */
  714.                         current_state = WhiteSpace;
  715.                         break;
  716.  
  717.                     case '*':
  718.                         /* this is also perhaps the end of comment */
  719.                         break;
  720.  
  721.                     case '\n':
  722.                         /* new line just increment state variables */
  723.                         (*line_number)++;
  724.  
  725.                     default:
  726.                         /* still part of the current comment */
  727.                         current_state = InComment;
  728.                         break;
  729.                 }
  730.                 break;
  731.  
  732.             case InCPPComment:
  733.                 if (c == '\n') {
  734.                     current_state = WhiteSpace;
  735.                     (*line_number)++;
  736.                 }
  737.                 break;
  738.  
  739.             case InQuoteNormal:
  740.                 switch (c) {
  741.  
  742.                     case '\"':
  743.                         /* end of InQuoteNormal state */
  744.                         current_state = Exit;
  745.                         break;
  746.  
  747.                     case '\\':
  748.                         /* InQuoteLiteral state */
  749.                         current_state = InQuoteLiteral;
  750.                         break;
  751.  
  752.                     default:
  753.                         /* normal dull behavior */
  754.                         break;
  755.                 }
  756.                 *t++ = c;
  757.                 token_length++;
  758.                 break;
  759.  
  760.             case InQuoteLiteral:
  761.                 /* this char is simply copied */
  762.                 current_state = InQuoteNormal;
  763.                 *t++ = c;
  764.                 token_length++;
  765.                 break;
  766.  
  767.             case InSingleQuoteNormal:
  768.                 switch (c) {
  769.  
  770.                     case '\\':
  771.                         /* InQuoteLiteral state */
  772.                         current_state = InSingleQuoteLiteral;
  773.                         break;
  774.  
  775.                     default:
  776.                         /* Just copy the character and move to close quote */
  777.                         current_state = EndSingleQuote;
  778.                         break;
  779.                 }
  780.                 *t++ = c;
  781.                 token_length++;
  782.                 break;
  783.  
  784.             case InSingleQuoteLiteral:
  785.                 /* this char is simply copied */
  786.                 current_state = EndSingleQuote;
  787.                 *t++ = c;
  788.                 token_length++;
  789.                 break;
  790.  
  791.             case EndSingleQuote:
  792.  
  793.                 /* end of InSingleQuote states */
  794.                 current_state = Exit;
  795.                 *t++ = c;
  796.                 token_length++;
  797.                 break;
  798.  
  799.             case Exit:
  800.                 *t = '\0';
  801.                 point--;
  802.                 return TRUE;
  803.                 break;
  804.  
  805.             default:            /* not reached */
  806.                 break;
  807.         }
  808.  
  809.         /* if the token_length has gotten too large then return */
  810.         if (token_length == max_token_length - 1) {
  811.             *t = '\0';
  812.             point--;
  813.             return TRUE;
  814.         }
  815.     }
  816. }
  817.  
  818.  
  819. /*----------------------------------------------------------------------------
  820.  *
  821.  * CFillToken() will obtain the next lexical parser from the buffer and move
  822.  * the token into the Token structure.  TRUE is returned if the lexical
  823.  * parser returns TRUE, otherwise FALSE is returned.
  824.  *
  825.  ---------------------------------------------------------------------------*/
  826.  
  827. BOOLEAN CFillToken(token, token_buffer)
  828.     Token *token;
  829.     Buffer *token_buffer;
  830. {
  831.     BOOLEAN token_found;
  832.  
  833.     /* obtain the next token */
  834.     token_found = CGetToken(token_buffer->inbuf,
  835.                             token->cur_token,
  836.                             MAX_TOKEN_LENGTH,
  837.                             &(token_buffer->token_line_location));
  838.  
  839.     /* if one is around then update the state for that token */
  840.     if (token_found) {
  841.         /* update location variables */
  842.         *(token->cur_char_location) = point;
  843.         *(token->cur_token_line) = token_buffer->token_line_location;
  844.     }
  845.  
  846.     return token_found;
  847. }
  848.  
  849.  
  850. /*----------------------------------------------------------------------------
  851.  *
  852.  * CTokenSwap() will swap the token variables and set the prev_ variables
  853.  * correctly
  854.  *
  855.  ---------------------------------------------------------------------------*/
  856.  
  857. CTokenSwap(token)
  858.     Token *token;
  859. {
  860.     char *charswap;             /* temporary swap variable */
  861.     int *longintswap;           /* temporary swap variable */
  862.  
  863.     /* swap the active token string */
  864.     charswap = token->cur_token;
  865.     token->cur_token = token->prev_token;
  866.     token->prev_token = charswap;
  867.  
  868.     /* swap the active character location */
  869.     longintswap = token->cur_char_location;
  870.     token->cur_char_location = token->prev_char_location;
  871.     token->prev_char_location = longintswap;
  872.  
  873.     /* swap the active line */
  874.     longintswap = token->cur_token_line;
  875.     token->cur_token_line = token->prev_token_line;
  876.     token->prev_token_line = longintswap;
  877. }
  878.  
  879.  
  880. /*----------------------------------------------------------------------------
  881.  *
  882.  * CDiscardLine() will move past all the characters up to the next EOL that
  883.  * is not preceded by a line continuation character.  This routine will
  884.  * return TRUE if there was a '(' character as the first character.  This
  885.  * return value is useful for determining if #defines are macros or simple
  886.  * defines.
  887.  *
  888.  ---------------------------------------------------------------------------*/
  889.  
  890. BOOLEAN CDiscardLine(inbuf, line_number)
  891.     char *inbuf;
  892.     int *line_number;
  893. {
  894.     char c;                     /* the current character being examined */
  895.  
  896.     BOOLEAN line_continue;      /* TRUE if line continuation true */
  897.     BOOLEAN is_macro;           /* TRUE if the first delimiter char is '(' */
  898.     BOOLEAN first_char;         /* TRUE when first character is active */
  899.  
  900.     /* init */
  901.     c = '\0';
  902.     line_continue = FALSE;
  903.     is_macro = FALSE;
  904.     first_char = TRUE;
  905.  
  906.     /* if the end of buffer is reached then return */
  907.     if (point == size())
  908.         return is_macro;
  909.  
  910.     /* loop until non continued EOL encountered */
  911.     do {
  912.  
  913.         /* determine if the first character is a '(' */
  914.         if (first_char) {
  915.             if (c == '(')
  916.                 is_macro = TRUE;
  917.             first_char = FALSE;
  918.         }
  919.  
  920.         /* handle the newline */
  921.         if (c == '\n') {
  922.             line_continue = FALSE;
  923.             (*line_number)++;
  924.         }
  925.  
  926.         c = curchar();
  927.         point++;
  928.  
  929.         if (c == '\\')
  930.             line_continue = TRUE;
  931.  
  932.  
  933.     } while (c != '\n' || line_continue);
  934.  
  935.     (*line_number)++;
  936.     return is_macro;
  937. }
  938.  
  939.  
  940. /*----------------------------------------------------------------------------
  941.  *
  942.  * CParseDefine() will parse macros and defines in standard C syntax
  943.  * distinguish between a macro and a define, if there is a punctuator '(',
  944.  * then it is a macro.  Take the token just before the first space or
  945.  * punctuator
  946.  *
  947.  ---------------------------------------------------------------------------*/
  948.  
  949. CParseDefine(token, token_buffer, infname, outbuf)
  950.     Token *token;
  951.     Buffer *token_buffer;
  952.     char *infname;
  953.     char *outbuf;
  954. {
  955.     SymbolType tmptype;         /* a temporay type variable */
  956.  
  957.     BOOLEAN token_found;
  958.     BOOLEAN is_macro;
  959.  
  960.     token_found = CFillToken(token, token_buffer);
  961.     if (token_found) {
  962.  
  963.         /* save the previous values */
  964.         CTokenSwap(token);
  965.  
  966.  
  967.         /* get rid of the rest of the line and return the define type */
  968.         is_macro =
  969.             CDiscardLine(token_buffer->inbuf,
  970.                          &(token_buffer->token_line_location));
  971.  
  972.         /* react on the token */
  973.         if (is_macro) {
  974.             tmptype = Macro;
  975.         }
  976.         else {
  977.             tmptype = Define;
  978.         }
  979.  
  980.         /* output the token */
  981.         COutputToken(token, token_buffer, tmptype,
  982.                      infname, outbuf);
  983.     }
  984. }
  985.  
  986.  
  987. /*----------------------------------------------------------------------------
  988.  *
  989.  * CParsePreprocessorDirective() will parse preprocessor directives in
  990.  * standard C syntax
  991.  *
  992.  ---------------------------------------------------------------------------*/
  993.  
  994. CParsePreprocessorDirective(token, token_buffer, infname, outbuf)
  995.     Token *token;
  996.     Buffer *token_buffer;
  997.     char *infname;
  998.     char *outbuf;
  999. {
  1000.     BOOLEAN token_found;
  1001.  
  1002.     token_found = CFillToken(token, token_buffer);
  1003.     if (token_found) {
  1004.  
  1005.         /* deal with a define directive */
  1006.         if (!strcmp(token->cur_token, "define")) {
  1007.             CParseDefine(token, token_buffer, infname, outbuf);
  1008.         }
  1009.         else {
  1010.  
  1011.             /* increment the else block level pointer */
  1012.             if (!strcmp(token->cur_token, "else")) {
  1013.                 token->else_nesting_level++;
  1014.             }
  1015.             else {
  1016.  
  1017.                 /* decrement the else block level pointer */
  1018.                 if (!strcmp(token->cur_token, "endif")) {
  1019.                     if (token->else_nesting_level)
  1020.                         token->else_nesting_level--;
  1021.                 }
  1022.                 else {
  1023.  
  1024.                     /* if an else has not already been seen then increment
  1025.                      * the level */
  1026.                     if (!strcmp(token->cur_token, "elif")) {
  1027.                         token->else_nesting_level++;
  1028.                     }
  1029.                 }
  1030.             }
  1031.  
  1032.             /* remove the rest of the directive line including line
  1033.              * continuation characters */
  1034.             CDiscardLine(token_buffer->inbuf,
  1035.                          &(token_buffer->token_line_location));
  1036.         }
  1037.     }
  1038. }
  1039.  
  1040.  
  1041. /*----------------------------------------------------------------------------
  1042.  *
  1043.  * CNextToken() will obtain the next token in the buffer and update the
  1044.  * appropriate variables.
  1045.  *
  1046.  ---------------------------------------------------------------------------*/
  1047.  
  1048. BOOLEAN CNextToken(token, token_buffer, infname, outbuf)
  1049.     Token *token;
  1050.     Buffer *token_buffer;
  1051.     char *infname;
  1052.     char *outbuf;
  1053. {
  1054.     BOOLEAN token_found;
  1055.     BOOLEAN cycle;
  1056.  
  1057.     do {
  1058.         /* obtain the next token */
  1059.         token_found = CFillToken(token, token_buffer);
  1060.  
  1061.         /* check for preprocessing directives and parse them if found */
  1062.         if (token->cur_token[0] == '#' && token_found) {
  1063.  
  1064.             /* parse the directive and loop back to get another token */
  1065.             CParsePreprocessorDirective(token, token_buffer, infname, outbuf);
  1066.             cycle = TRUE;
  1067.         }
  1068.         else {
  1069.  
  1070.             /* we found a token to pass to the semantic parser */
  1071.             cycle = FALSE;
  1072.         }
  1073.     } while (cycle);
  1074.  
  1075.     /* return it */
  1076.     return token_found;
  1077. }
  1078.  
  1079.  
  1080. /*----------------------------------------------------------------------------
  1081.  *
  1082.  * CToLevelZero() will increment the nesting level and then parse tokens
  1083.  * until level zero has been reached again.  If tokens are no longer
  1084.  * available this loop will stop.
  1085.  *
  1086.  ---------------------------------------------------------------------------*/
  1087.  
  1088. CToLevelZero(token, token_buffer, infname, outbuf)
  1089.     Token *token;
  1090.     Buffer *token_buffer;
  1091.     char *infname;
  1092.     char *outbuf;
  1093. {
  1094.     int nesting_level = 1;
  1095.  
  1096.     token->else_nesting_level = 0;
  1097.  
  1098.     while (nesting_level) {
  1099.         if (CGetToken(token_buffer->inbuf, token->cur_token,
  1100.                       MAX_TOKEN_LENGTH,
  1101.                       &(token_buffer->token_line_location))) {
  1102.             if (token->cur_token[0] == '#') {
  1103.                 CParsePreprocessorDirective(token, token_buffer,
  1104.                                             infname, outbuf);
  1105.             }
  1106.             else {
  1107.  
  1108.                 /* only count open brace, parens and brackets within blocks
  1109.                  * of one element of an ifdef code block */
  1110.                 if (!token->else_nesting_level) {
  1111.                     if (strchr(C_open_brace, token->cur_token[0]))
  1112.                         nesting_level++;
  1113.                     else
  1114.                         if (strchr(C_close_brace, token->cur_token[0]))
  1115.                             nesting_level--;
  1116.                 }
  1117.             }
  1118.         }
  1119.         else
  1120.             nesting_level = 0;
  1121.     }
  1122. }
  1123.  
  1124.  
  1125. /*----------------------------------------------------------------------------
  1126.  *
  1127.  * CToPunctuator() will parse tokens until the next punctuator has been
  1128.  * reached.  If tokens are no longer available this loop will stop.  If this
  1129.  * loop is successful the found flag declared in the host routine will be
  1130.  * set.
  1131.  *
  1132.  ---------------------------------------------------------------------------*/
  1133.  
  1134. BOOLEAN CToPunctuator(token, token_buffer, infname, outbuf)
  1135.     Token *token;
  1136.     Buffer *token_buffer;
  1137.     char *infname;
  1138.     char *outbuf;
  1139. {
  1140.     BOOLEAN punctuator_found;
  1141.  
  1142.     /* init and parse through until the first punctuator is found */
  1143.     token->token_count = 0;
  1144.     punctuator_found = FALSE;
  1145.     while (!punctuator_found) {
  1146.         token->token_count++;
  1147.         CTokenSwap(token);
  1148.         if (!CNextToken(token, token_buffer, infname, outbuf)) {
  1149.             break;
  1150.         }
  1151.         else {
  1152.             if (IsPunctuator(token->cur_token[0]))
  1153.                 punctuator_found = TRUE;
  1154.         }
  1155.     }
  1156.  
  1157.     /* return value */
  1158.     return punctuator_found;
  1159. }
  1160.  
  1161.  
  1162. /*----------------------------------------------------------------------------
  1163.  *
  1164.  * CParseParens() will move through a declaration in parentheses and place
  1165.  * the correct valid token as prev_token.  This return TRUE if a '[' was seen
  1166.  * within the parens and false otherwise.
  1167.  *
  1168.  ---------------------------------------------------------------------------*/
  1169.  
  1170. BOOLEAN CParseParens(token, token_buffer, infname, outbuf)
  1171.     Token *token;
  1172.     Buffer *token_buffer;
  1173.     char *infname;
  1174.     char *outbuf;
  1175. {
  1176.     BOOLEAN token_found;
  1177.     BOOLEAN variable_seen;
  1178.     int brace_ignore = 1;
  1179.  
  1180.     token->else_nesting_level = 0;
  1181.  
  1182.     token_found = TRUE;
  1183.     variable_seen = FALSE;
  1184.     while (brace_ignore &&
  1185.            token_found) {
  1186.  
  1187.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  1188.  
  1189.         if (token_found &&
  1190.             !token->else_nesting_level) {
  1191.             switch (token->cur_token[0]) {
  1192.  
  1193.                 case '(':
  1194.  
  1195.                     /* increment brace_ignore and continue */
  1196.                     brace_ignore++;
  1197.                     break;
  1198.  
  1199.                 case ')':
  1200.  
  1201.                     /* just decrement brace_ignore if it is positive. If
  1202.                      * brace ignore is not positive at this point then we
  1203.                      * certainly have a syntax error.  Ignore this fact if
  1204.                      * so. */
  1205.                     if (brace_ignore) {
  1206.                         brace_ignore--;
  1207.                     }
  1208.                     break;
  1209.  
  1210.                 case '[':
  1211.  
  1212.                     /* move to end of array bounds */
  1213.                     variable_seen = TRUE;
  1214.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1215.                     break;
  1216.  
  1217.                 default:
  1218.                     CTokenSwap(token);
  1219.                     break;
  1220.             }
  1221.         }
  1222.     }
  1223.  
  1224.     return variable_seen;
  1225. }
  1226.  
  1227.  
  1228. /*----------------------------------------------------------------------------
  1229.  *
  1230.  * COutputCommaDelimitedToken() will output a token and then parse the
  1231.  * statement until ';' or ',' is reached.  The token is output if the passed
  1232.  * token type is requested from the command line.
  1233.  *
  1234.  ---------------------------------------------------------------------------*/
  1235.  
  1236. COutputCommaDelimitedToken(token, token_buffer, token_type, infname, outbuf)
  1237.     Token *token;
  1238.     Buffer *token_buffer;
  1239.     SymbolType token_type;
  1240.     char *infname;
  1241.     char *outbuf;
  1242. {
  1243.     BOOLEAN punctuator_found;
  1244.  
  1245.     /* output the token */
  1246.     COutputToken(token, token_buffer, token_type, infname, outbuf);
  1247.  
  1248.     /* go to the next list punctuator (',' or ';') */
  1249.     punctuator_found = TRUE;
  1250.     while (token->cur_token[0] != ',' &&
  1251.            token->cur_token[0] != ';' &&
  1252.            punctuator_found) {
  1253.         if (strchr(C_open_brace, token->cur_token[0])) {
  1254.             CToLevelZero(token, token_buffer, infname, outbuf);
  1255.         }
  1256.         punctuator_found = CToPunctuator(token, token_buffer,
  1257.                                          infname, outbuf);
  1258.     }
  1259. }
  1260.  
  1261.  
  1262. /*----------------------------------------------------------------------------
  1263.  *
  1264.  * CParseCommaDelimitedList() will parse a token list seperated by commas
  1265.  * until a ';' is found.  The tokens are output if the passed type is
  1266.  * requested from the command line.
  1267.  *
  1268.  ---------------------------------------------------------------------------*/
  1269.  
  1270. CParseCommaDelimitedList(token, token_buffer, token_type, infname, outbuf)
  1271.     Token *token;
  1272.     Buffer *token_buffer;
  1273.     SymbolType token_type;
  1274.     char *infname;
  1275.     char *outbuf;
  1276. {
  1277.     BOOLEAN punctuator_found;
  1278.  
  1279.     /* parse through the list */
  1280.     punctuator_found = TRUE;
  1281.     while (token->cur_token[0] != ';' &&
  1282.            punctuator_found) {
  1283.         punctuator_found = CToPunctuator(token, token_buffer,
  1284.                                          infname, outbuf);
  1285.         if (punctuator_found) {
  1286.             switch (token->cur_token[0]) {
  1287.  
  1288.                 case '(':
  1289.                     /* this is an embedded variable declaration, either a
  1290.                      * complex variable pointer or function pointer, fall
  1291.                      * through after picking out the internal token */
  1292.                     CParseParens(token, token_buffer, infname, outbuf);
  1293.  
  1294.                 case '[':
  1295.                 case ',':
  1296.                 case ';':
  1297.                 case '=':
  1298.  
  1299.                     /* this is one of the proper ending tokens for this type
  1300.                      * of declaration list, so output it and parse to the
  1301.                      * next correct punctuator */
  1302.                     COutputToken(token, token_buffer, token_type,
  1303.                                  infname, outbuf);
  1304.                     while (token->cur_token[0] != ',' &&
  1305.                            token->cur_token[0] != ';' &&
  1306.                            punctuator_found) {
  1307.                         if (strchr(C_open_brace, token->cur_token[0])) {
  1308.                             CToLevelZero(token, token_buffer,
  1309.                                          infname, outbuf);
  1310.                         }
  1311.                         punctuator_found = CToPunctuator(token, token_buffer,
  1312.                                                          infname, outbuf);
  1313.                     }
  1314.                     break;
  1315.                 default:
  1316.                     break;
  1317.             }
  1318.         }
  1319.     }
  1320. }
  1321.  
  1322.  
  1323. /*----------------------------------------------------------------------------
  1324.  *
  1325.  * CParseFunctionOrGlobalVariable() will parse a function, prototype or
  1326.  * global variable syntax.
  1327.  *
  1328.  ---------------------------------------------------------------------------*/
  1329.  
  1330. CParseFunctionOrGlobalVariable(token, token_buffer, infname, outbuf)
  1331.     Token *token;
  1332.     Buffer *token_buffer;
  1333.     char *infname;
  1334.     char *outbuf;
  1335. {
  1336.     char *line_buf;             /* the first token buffer */
  1337.     int charloc;                /* the char location of sbuf1 */
  1338.     int tokenline;              /* the line number of sbuf1 */
  1339.  
  1340.     BOOLEAN token_found;
  1341.     BOOLEAN punctuator_found;
  1342.     BOOLEAN last_token_known;
  1343.     BOOLEAN variable_seen;
  1344.  
  1345.     /* init */
  1346.     charloc = 0;
  1347.     tokenline = 1;
  1348.     line_buf = malloc(MAX_TOKEN_LENGTH);
  1349.     line_buf[0] = '\0';
  1350.  
  1351.     /* save the previous token */
  1352.     last_token_known = CIsDeclarationToken(token->prev_token);
  1353.     if (!last_token_known) {
  1354.  
  1355.         /* If this is not a known token then it may be a function name. Save
  1356.          * it then look further at the syntax.  This also may be a symbol
  1357.          * previously defined via a typedef which alters the syntax of C/C++ */
  1358.         strcpy(line_buf, token->prev_token);
  1359.         charloc = *(token->prev_char_location);
  1360.         tokenline = *(token->prev_token_line);
  1361.     }
  1362.  
  1363.     /* This is a function or prototype or global variable go to brace_ignore
  1364.      * level zero again. */
  1365.     variable_seen = CParseParens(token, token_buffer, infname, outbuf);
  1366.  
  1367.     /* Check to see if this is a function, prototype, or global variable. If
  1368.      * the token is a ';' and last_token_known is false then we assume a
  1369.      * function.  Strange variable declarations may fool this, but not
  1370.      * likely. If the character is a '(' then it is certainly a function or
  1371.      * prototype unless variable_seen is TRUE, then it is a variable. If the
  1372.      * character is a '[', ',' then it is certainly a variable declaration.
  1373.      * If the character is a ';' and last_token_known is true then it is a
  1374.      * variable declaration.  If the token is anything else then it is a
  1375.      * function. */
  1376.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  1377.     if (token_found) {
  1378.         switch (token->cur_token[0]) {
  1379.  
  1380.             case ';':
  1381.  
  1382.                 /* determine if a prototype or a variable declaration. if the
  1383.                  * last_token_known is true then it is a global variable.  If
  1384.                  * the token was a symbol defined by a typedef then this
  1385.                  * distinction is incorrect since typedef actually alters
  1386.                  * syntax.  This is correct for the large majority of cases
  1387.                  * since most do not enclose simple variable declarations in
  1388.                  * parens. */
  1389.                 if (last_token_known) {
  1390.  
  1391.                     /* this is a global variable */
  1392.                     COutputToken(token, token_buffer, GlobalVariable,
  1393.                                  infname, outbuf);
  1394.                 }
  1395.                 else {
  1396.  
  1397.                     /* this is a prototype, copy saved token back to
  1398.                      * prev_token, output and continue */
  1399.                     strcpy(token->prev_token, line_buf);
  1400.                     *(token->prev_char_location) = charloc;
  1401.                     *(token->prev_token_line) = tokenline;
  1402.                     COutputToken(token, token_buffer, ProtoType,
  1403.                                  infname, outbuf);
  1404.                 }
  1405.                 break;
  1406.  
  1407.             case '(':
  1408.  
  1409.                 if (variable_seen) {
  1410.  
  1411.                     /* this is a variable declaration */
  1412.                     COutputCommaDelimitedToken(token, token_buffer,
  1413.                                                GlobalVariable,
  1414.                                                infname, outbuf);
  1415.                     CParseCommaDelimitedList(token, token_buffer,
  1416.                                              GlobalVariable,
  1417.                                              infname, outbuf);
  1418.                 }
  1419.                 else {
  1420.  
  1421.                     /* move to level zero again */
  1422.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1423.  
  1424.                     /* obtain the next token */
  1425.                     token_found = CNextToken(token, token_buffer,
  1426.                                              infname, outbuf);
  1427.  
  1428.                     if (token_found) {
  1429.  
  1430.                         /* check if prototype, function or function pointer
  1431.                          * variable declaration */
  1432.                         switch (token->cur_token[0]) {
  1433.  
  1434.                             case '=':
  1435.  
  1436.                                 /* this is a function pointer variable
  1437.                                  * declaration */
  1438.                                 COutputCommaDelimitedToken(token,
  1439.                                                            token_buffer,
  1440.                                                            GlobalVariable,
  1441.                                                            infname, outbuf);
  1442.                                 CParseCommaDelimitedList(token, token_buffer,
  1443.                                                          GlobalVariable,
  1444.                                                          infname, outbuf);
  1445.                                 break;
  1446.  
  1447.                             case ';':
  1448.  
  1449.                                 /* this is a prototype, output it */
  1450.                                 COutputToken(token, token_buffer,
  1451.                                              ProtoType, infname, outbuf);
  1452.                                 break;
  1453.  
  1454.                             default:
  1455.  
  1456.                                 /* this is a function */
  1457.                                 COutputToken(token, token_buffer,
  1458.                                              Function, infname, outbuf);
  1459.  
  1460.                                 /* parse through function */
  1461.                                 punctuator_found = TRUE;
  1462.                                 while (token->cur_token[0] != '{' &&
  1463.                                        punctuator_found) {
  1464.                                     punctuator_found =
  1465.                                         CToPunctuator(token, token_buffer,
  1466.                                                       infname, outbuf);
  1467.                                 }
  1468.                                 if (punctuator_found) {
  1469.                                     CToLevelZero(token, token_buffer,
  1470.                                                  infname, outbuf);
  1471.                                 }
  1472.                                 break;
  1473.                         }
  1474.                     }
  1475.                 }
  1476.                 break;
  1477.  
  1478.             case '[':
  1479.             case '=':
  1480.             case ',':
  1481.  
  1482.                 /* global variables */
  1483.                 COutputCommaDelimitedToken(token, token_buffer,
  1484.                                            GlobalVariable,
  1485.                                            infname, outbuf);
  1486.                 CParseCommaDelimitedList(token, token_buffer,
  1487.                                          GlobalVariable,
  1488.                                          infname, outbuf);
  1489.                 break;
  1490.  
  1491.             default:
  1492.  
  1493.                 /* this is a function, copy saved token back to prev_token,
  1494.                  * output and continue */
  1495.                 strcpy(token->prev_token, line_buf);
  1496.                 *(token->prev_char_location) = charloc;
  1497.                 *(token->prev_token_line) = tokenline;
  1498.                 COutputToken(token, token_buffer,
  1499.                              Function, infname, outbuf);
  1500.  
  1501.                 /* parse through function */
  1502.                 punctuator_found = TRUE;
  1503.                 while (token->cur_token[0] != '{' &&
  1504.                        punctuator_found) {
  1505.                     punctuator_found =
  1506.                         CToPunctuator(token, token_buffer, infname, outbuf);
  1507.                 }
  1508.                 if (punctuator_found) {
  1509.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1510.                 }
  1511.                 break;
  1512.         }
  1513.     }
  1514.     free(line_buf);
  1515. }
  1516.  
  1517.  
  1518. /*----------------------------------------------------------------------------
  1519.  *
  1520.  * CParseNOP() will parse an as of yet unrecognized statement.  If I run into
  1521.  * a punctuator at this time then I have found either a structure declaration
  1522.  * (C++ 2.0), or a global variable declaration.  If the punctuator is '[',
  1523.  * ',', '=', or ';' then it is a global variable declaration.  If the
  1524.  * punctuator is a '{' then we have a structure declaration at this time we
  1525.  * should not run into any closing punctuators or syntax is in a bad way
  1526.  *
  1527.  ---------------------------------------------------------------------------*/
  1528.  
  1529. CParseNOP(token, token_buffer, infname, outbuf)
  1530.     Token *token;
  1531.     Buffer *token_buffer;
  1532.     char *infname;
  1533.     char *outbuf;
  1534. {
  1535.     BOOLEAN token_found;
  1536.  
  1537.     switch (token->cur_token[0]) {
  1538.         case ';':
  1539.         case '=':
  1540.         case ',':
  1541.         case '[':
  1542.  
  1543.             /* global variables are here */
  1544.             COutputCommaDelimitedToken(token, token_buffer,
  1545.                                        GlobalVariable,
  1546.                                        infname, outbuf);
  1547.             CParseCommaDelimitedList(token, token_buffer,
  1548.                                      GlobalVariable,
  1549.                                      infname, outbuf);
  1550.             token->extern_active = FALSE;
  1551.             token->CPP_extern_active = FALSE;
  1552.             token->static_active = FALSE;
  1553.             break;
  1554.  
  1555.         case '{':
  1556.  
  1557.             /* validate we are not in a C++ extern for C statements */
  1558.              if (!token->CPP_extern_active) {
  1559.                  
  1560.                 /* this is a structure (C++ syntax) */
  1561.                  /* output it */
  1562.                  COutputToken(token, token_buffer, Structure,
  1563.                               infname, outbuf);
  1564.  
  1565.                  /* move through declaration */
  1566.                  CToLevelZero(token, token_buffer, infname, outbuf);
  1567.  
  1568.                  /* get the next token */
  1569.                  token_found = CNextToken(token, token_buffer,
  1570.                                           infname, outbuf);
  1571.  
  1572.                  /* if a token is available then output the list */
  1573.                  if (token_found) {
  1574.                      CParseCommaDelimitedList(token, token_buffer,
  1575.                                               GlobalVariable,
  1576.                                               infname, outbuf);
  1577.                  }                                                      
  1578.                  token->extern_active = FALSE;
  1579.                  token->static_active = FALSE;
  1580.              }
  1581.             break;
  1582.  
  1583.         case '(':
  1584.  
  1585.             CParseFunctionOrGlobalVariable(token, token_buffer,
  1586.                                            infname, outbuf);
  1587.             token->extern_active = FALSE;
  1588.             token->CPP_extern_active = FALSE;
  1589.             token->static_active = FALSE;
  1590.             break;
  1591.  
  1592.          case '"':
  1593.                                              
  1594.              if (!strcmp("\"C\"",token->cur_token))
  1595.                  token->CPP_extern_active = TRUE;
  1596.              break;
  1597.              
  1598.         default:
  1599.  
  1600.             /* true NOP */
  1601.             break;
  1602.     }
  1603. }
  1604.  
  1605.  
  1606. /*----------------------------------------------------------------------------
  1607.  *
  1608.  * CParseEnumerationConstants() will parse constants within an enumeration
  1609.  * declaration
  1610.  *
  1611.  ---------------------------------------------------------------------------*/
  1612.  
  1613. CParseEnumerationConstants(token, token_buffer, infname, outbuf)
  1614.     Token *token;
  1615.     Buffer *token_buffer;
  1616.     char *infname;
  1617.     char *outbuf;
  1618. {
  1619.     BOOLEAN punctuator_found;
  1620.  
  1621.     char *open_brace = "({[";
  1622.  
  1623.     /* obtain the enumeration constants */
  1624.     punctuator_found = TRUE;
  1625.  
  1626.     while (token->cur_token[0] != '}' &&
  1627.            punctuator_found) {
  1628.         punctuator_found = CToPunctuator(token, token_buffer,
  1629.                                          infname, outbuf);
  1630.         if (punctuator_found) {
  1631.             switch (token->cur_token[0]) {
  1632.  
  1633.                 case ',':
  1634.                 case '=':
  1635.  
  1636.                     /* this is one of the proper ending tokens for this type
  1637.                      * of declaration list, so output it and parse to the
  1638.                      * next correct punctuator */
  1639.                     COutputToken(token, token_buffer, EnumerationConstant,
  1640.                                  infname, outbuf);
  1641.                     while (token->cur_token[0] != ',' &&
  1642.                            token->cur_token[0] != '}' &&
  1643.                            punctuator_found) {
  1644.                         if (strchr(open_brace, token->cur_token[0])) {
  1645.                             CToLevelZero(token, token_buffer,
  1646.                                          infname, outbuf);
  1647.                         }
  1648.                         punctuator_found = CToPunctuator(token, token_buffer,
  1649.                                                          infname, outbuf);
  1650.                     }
  1651.                     break;
  1652.  
  1653.                 default:
  1654.                     break;
  1655.             }
  1656.         }
  1657.     }
  1658. }
  1659.  
  1660.  
  1661. /*----------------------------------------------------------------------------
  1662.  *
  1663.  * CParseDeclarationStatement() will parse struct, enum and union
  1664.  * declarations.  take the token just before the first punctuator, run
  1665.  * through the top level braces and parse for variables if the first
  1666.  * punctuator is a ';' then this is a global variable declaration, if the
  1667.  * first token[0] is a '{' then this is a global variable declaration.
  1668.  *
  1669.  ---------------------------------------------------------------------------*/
  1670.  
  1671. CParseDeclarationStatement(token, token_buffer, type, infname, outbuf)
  1672.     Token *token;
  1673.     Buffer *token_buffer;
  1674.     SymbolType type;
  1675.     char *infname;
  1676.     char *outbuf;
  1677. {
  1678.     BOOLEAN token_found;
  1679.     BOOLEAN punctuator_found;
  1680.     BOOLEAN primary_parse;
  1681.  
  1682.     punctuator_found = CToPunctuator(token, token_buffer, infname, outbuf);
  1683.     if (punctuator_found) {
  1684.  
  1685.         /* init */
  1686.         primary_parse = TRUE;
  1687.  
  1688.         /* switch on current token */
  1689.         switch (token->cur_token[0]) {
  1690.  
  1691.                 /* this is truly an object declaration */
  1692.             case '{':
  1693.  
  1694.                 /* output only if this is not a variable declaration */
  1695.                 if (token->token_count != 1) {
  1696.  
  1697.                     /* output it */
  1698.                     COutputToken(token, token_buffer, type, infname, outbuf);
  1699.                 }
  1700.  
  1701.                 /* check if enumeration */
  1702.                 if (type == Enumeration) {
  1703.  
  1704.                     /* obtain the enumeration constants */
  1705.                     CParseEnumerationConstants(token, token_buffer,
  1706.                                                infname, outbuf);
  1707.                 }
  1708.                 else {
  1709.  
  1710.                     /* move through declaration and fall through */
  1711.                     CToLevelZero(token, token_buffer, infname, outbuf);
  1712.                 }
  1713.  
  1714.                 /* get the next token, if one not available then break out of
  1715.                  * case */
  1716.                 token_found = CNextToken(token, token_buffer,
  1717.                                          infname, outbuf);
  1718.                 if (!token_found)
  1719.                     break;
  1720.  
  1721.                 /* fall through to take care of variable declarations after
  1722.                  * setting pre-parse flag */
  1723.                 primary_parse = FALSE;
  1724.  
  1725.             case ';':
  1726.             case '=':
  1727.             case ',':
  1728.             case '[':
  1729.  
  1730.                 /* if this is the first seen then output it */
  1731.                 if (primary_parse) {
  1732.                     COutputCommaDelimitedToken(token, token_buffer,
  1733.                                                GlobalVariable,
  1734.                                                infname, outbuf);
  1735.                 }
  1736.  
  1737.                 CParseCommaDelimitedList(token, token_buffer,
  1738.                                          GlobalVariable,
  1739.                                          infname, outbuf);
  1740.                 break;
  1741.  
  1742.             case '(':
  1743.  
  1744.                 CParseFunctionOrGlobalVariable(token, token_buffer,
  1745.                                                infname, outbuf);
  1746.                 break;
  1747.  
  1748.             default:
  1749.  
  1750.                 /* not reached */
  1751.                 break;
  1752.         }
  1753.     }
  1754. }
  1755.  
  1756.  
  1757. /*----------------------------------------------------------------------------
  1758.  *
  1759.  * CParseTypeDefinition() parses the typedef statement.  take the token just
  1760.  * before the first *correct* punctuator, the ';', ',' or the '['.  Tag any
  1761.  * declarations being done here, get the next token
  1762.  *
  1763.  ---------------------------------------------------------------------------*/
  1764.  
  1765. CParseTypeDefinition(token, token_buffer, infname, outbuf)
  1766.     Token *token;
  1767.     Buffer *token_buffer;
  1768.     char *infname;
  1769.     char *outbuf;
  1770. {
  1771.     BOOLEAN token_found;
  1772.     BOOLEAN parens_found;
  1773.     BOOLEAN special_found;
  1774.  
  1775.     int token_count;
  1776.     SymbolType tmptype;
  1777.  
  1778.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  1779.  
  1780.     if (token_found) {
  1781.  
  1782.         /* check the type of the token for future use */
  1783.         tmptype = CTokenType(token->cur_token);
  1784.  
  1785.         /* parse the typedef */
  1786.         parens_found = FALSE;
  1787.         special_found = FALSE;
  1788.         token_count = 0;
  1789.         while (token->cur_token[0] != ';' &&
  1790.                token->cur_token[0] != ',' &&
  1791.                token->cur_token[0] != '[' &&
  1792.                token_found &&
  1793.                !special_found) {
  1794.  
  1795.             /* parse for defines */
  1796.             if (token_found) {
  1797.  
  1798.                 /* handle the punctuator */
  1799.                 switch (token->cur_token[0]) {
  1800.  
  1801.                     case '{':
  1802.  
  1803.                         /* pass through any defines going on here */
  1804.                         if (token->cur_token[0] == '{') {
  1805.  
  1806.                             /* if the token count is > 1 here then we have a
  1807.                              * named declaration and need to output the
  1808.                              * token, output only if the token type is enum,
  1809.                              * struct, or union */
  1810.                             if (token_count > 1 &&
  1811.                                 (tmptype == Structure ||
  1812.                                  tmptype == Enumeration ||
  1813.                                  tmptype == Union)) {
  1814.                                 COutputToken(token, token_buffer,
  1815.                                              tmptype, infname, outbuf);
  1816.                             }
  1817.  
  1818.                             /* check if enumeration */
  1819.                             if (tmptype == Enumeration) {
  1820.  
  1821.                                 /* obtain the enumeration constants */
  1822.                                 CParseEnumerationConstants(token,
  1823.                                                            token_buffer,
  1824.                                                            infname, outbuf);
  1825.                             }
  1826.                             else {
  1827.  
  1828.                                 /* go back to level 0 */
  1829.                                 CToLevelZero(token, token_buffer,
  1830.                                              infname, outbuf);
  1831.                             }
  1832.                         }
  1833.                         break;
  1834.  
  1835.                     case '(':
  1836.  
  1837.                         /* if this is the top level and we have already been
  1838.                          * through a set of parens then we know this to be a
  1839.                          * function typedef so we ouput the previous token,
  1840.                          * otherwise check the previous token and if it is a
  1841.                          * known keyword then just eat the token and continue */
  1842.                         if (parens_found) {
  1843.                             COutputToken(token, token_buffer,
  1844.                                          TypeDefinition, infname, outbuf);
  1845.                             CToLevelZero(token, token_buffer,
  1846.                                          infname, outbuf);
  1847.                             special_found = TRUE;
  1848.                         }
  1849.                         else {
  1850.  
  1851.                             /* Move back to the top level */
  1852.                             CParseParens(token, token_buffer,
  1853.                                          infname, outbuf);
  1854.  
  1855.                             /* next paren we find we know we have a token */
  1856.                             parens_found = TRUE;
  1857.  
  1858.                             /* swap to prevent loss of token */
  1859.                             CTokenSwap(token);
  1860.                         }
  1861.                         break;
  1862.  
  1863.                     default:
  1864.  
  1865.                         /* if we have another token after a paren parse then
  1866.                          * we know the token in the parens was nothing
  1867.                          * special */
  1868.                         parens_found = FALSE;
  1869.                         break;
  1870.                 }
  1871.             }
  1872.  
  1873.             /* get another token */
  1874.             CTokenSwap(token);
  1875.             token_found = CNextToken(token, token_buffer, infname, outbuf);
  1876.             token_count++;
  1877.         }
  1878.  
  1879.         /* output the typedef names if appropriate */
  1880.         if (token->prev_token[0] != '}' &&
  1881.             token_found) {
  1882.  
  1883.             /* don't output the first token if already done */
  1884.             if (!special_found) {
  1885.                 COutputCommaDelimitedToken(token, token_buffer,
  1886.                                            TypeDefinition,
  1887.                                            infname, outbuf);
  1888.             }
  1889.  
  1890.             /* parse through the rest of the typedef names */
  1891.             CParseCommaDelimitedList(token, token_buffer,
  1892.                                      TypeDefinition,
  1893.                                      infname, outbuf);
  1894.         }
  1895.     }
  1896. }
  1897.  
  1898.  
  1899. /*----------------------------------------------------------------------------
  1900.  *
  1901.  * CParseClass() will parse the C++ class syntax.  take the token just before
  1902.  * the first '{', ',' or ':' and run through the top level braces if there
  1903.  *
  1904.  ---------------------------------------------------------------------------*/
  1905.  
  1906. CParseClass(token, token_buffer, infname, outbuf)
  1907.     Token *token;
  1908.     Buffer *token_buffer;
  1909.     char *infname;
  1910.     char *outbuf;
  1911. {
  1912.     BOOLEAN token_found;
  1913.  
  1914.     token_found = TRUE;
  1915.     while (token->cur_token[0] != '{' &&
  1916.            token->cur_token[0] != ':' &&
  1917.            token->cur_token[0] != ';' &&
  1918.            token_found) {
  1919.  
  1920.         /* save the current token */
  1921.         CTokenSwap(token);
  1922.  
  1923.         /* get the next token */
  1924.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  1925.     }
  1926.  
  1927.     /* output the class name */
  1928.     if (token_found) {
  1929.         COutputToken(token, token_buffer, Class, infname, outbuf);
  1930.  
  1931.         /* parse through the remainder of the statement */
  1932.         while (token->cur_token[0] != ';' &&
  1933.                token_found) {
  1934.             if (token->cur_token[0] == '{') {
  1935.  
  1936.                 /* move back to the zero level */
  1937.                 CToLevelZero(token, token_buffer, infname, outbuf);
  1938.             }
  1939.  
  1940.             token_found = CNextToken(token, token_buffer, infname, outbuf);
  1941.         }
  1942.     }
  1943. }
  1944.  
  1945.  
  1946. /*----------------------------------------------------------------------------
  1947.  *
  1948.  * CTags() tags an input stream assuming standard ANSI 2.0 C/C++ syntax.
  1949.  * Long tokens are allowed, ANSI requires only 31 significant, note that if
  1950.  * token length exceeds MAX_TOKEN_LENGTH this parser will die a horrible
  1951.  * death (or at the very least do ugly things to someone else's memory),
  1952.  * with the large size of MAX_TOKEN_LENGTH, anyone caught on this hook
  1953.  * deserves what they get...
  1954.  *
  1955.  ---------------------------------------------------------------------------*/
  1956.  
  1957. CTags(inbuf, infname, outbuf)
  1958.     char *inbuf;
  1959.     char *infname;
  1960.     char *outbuf;
  1961. {
  1962.     SymbolType type;            /* the type of the current token */
  1963.  
  1964.     Token *token;               /* current state variable */
  1965.     Buffer *token_buffer;       /* input buffer */
  1966.  
  1967.     BOOLEAN token_found;        /* set by CNextToken() */
  1968.  
  1969.     /* allocate the Buffer and Token memory */
  1970.     token = (Token *) malloc(sizeof(Token));
  1971.     token_buffer = (Buffer *) malloc(sizeof(Token));
  1972.  
  1973.     /* init the parser engine */
  1974.     point = 0;
  1975.     CParserInit();
  1976.     token->token_count = 0;
  1977.  
  1978.     /* init the current token buffers */
  1979.     token->cur_token = token->sbuf1;
  1980.     token->cur_char_location = &(token->charloc1);
  1981.     token->cur_token_line = &(token->tokenline1);
  1982.     token->cur_token[0] = '\0';
  1983.     *(token->cur_char_location) = 0;
  1984.     *(token->cur_token_line) = 1;
  1985.  
  1986.     /* init the previous token buffers */
  1987.     token->prev_token = token->sbuf2;
  1988.     token->prev_char_location = &(token->charloc2);
  1989.     token->prev_token_line = &(token->tokenline2);
  1990.     token->prev_token[0] = '\0';
  1991.     *(token->prev_char_location) = 0;
  1992.     *(token->prev_token_line) = 1;
  1993.  
  1994.     /* init the input buffers */
  1995.     token_buffer->token_line_location = 1;
  1996.     token_buffer->inbuf = inbuf;
  1997.  
  1998.     /* init Extern and Static state */
  1999.     token->extern_active = FALSE;
  2000.     token->CPP_extern_active = FALSE;
  2001.     token->static_active = FALSE;
  2002.  
  2003.     /* get the first token */
  2004.     token_found = CNextToken(token, token_buffer, infname, outbuf);
  2005.  
  2006.     /* loop through the file */
  2007.     while (token_found) {
  2008.  
  2009.         /* obtain the token type */
  2010.         type = CTokenType(token->cur_token);
  2011.  
  2012.         /* react on the token type */
  2013.         switch (type) {
  2014.  
  2015.             case NOP:
  2016.                 CParseNOP(token, token_buffer, infname, outbuf);
  2017.                 break;
  2018.  
  2019.             case Structure:
  2020.             case Enumeration:
  2021.             case Union:
  2022.                 CParseDeclarationStatement(token, token_buffer,
  2023.                                            type, infname, outbuf);
  2024.                 break;
  2025.  
  2026.             case TypeDefinition:
  2027.                 CParseTypeDefinition(token, token_buffer, infname, outbuf);
  2028.                 break;
  2029.  
  2030.             case Class:
  2031.                 CParseClass(token, token_buffer, infname, outbuf);
  2032.                 break;
  2033.  
  2034.             case Extern:
  2035.                 token->extern_active = TRUE;
  2036.                 break;
  2037.  
  2038.             case Static:
  2039.                 token->static_active = TRUE;
  2040.                 break;
  2041.  
  2042.             default:
  2043.                 /* not reached */
  2044.                 break;
  2045.         }
  2046.  
  2047.         if (type != Extern &&
  2048.             type != Static &&
  2049.             type != NOP) {
  2050.  
  2051.             /* turn off the extern flag */
  2052.             token->extern_active = FALSE;
  2053.             token->CPP_extern_active = FALSE;
  2054.             token->static_active = FALSE;
  2055.         }
  2056.  
  2057.         /* swap state variables and get the next token */
  2058.         CTokenSwap(token);
  2059.         token_found = CNextToken(token, token_buffer, infname, outbuf);
  2060.     }
  2061.  
  2062.     free(token);
  2063.     free(token_buffer);
  2064. }
  2065.  
  2066.  
  2067. /*----------------------------------------------------------------------------
  2068.  *
  2069.  * tag_suffix_c(), tag_suffix_h() and tag_suffix_e() are recognized procedure
  2070.  * names to the tags package in Epsilon and will be called automatically when
  2071.  * tagging needs to happen for these extensions.  These are replacement names
  2072.  * for the routines of the same name defined in tags.e.
  2073.  *
  2074.  ---------------------------------------------------------------------------*/
  2075.  
  2076. tag_suffix_c()
  2077. {
  2078.     /* the third parameter, the output buffer name is not actually used by
  2079.      * anyone but is left here for a time when this information may be
  2080.      * needed.  The current algorithm is to let the funtion add_tag() decide
  2081.      * the buffer name to send the output to.  As a little more than
  2082.      * coincedence, the name used here is the same used in add_tag() defined
  2083.      * in tags.e */
  2084.     CTags(bufname, filename, "-tags");
  2085. }
  2086.  
  2087. tag_suffix_h()
  2088. {
  2089.     tag_suffix_c();
  2090. }
  2091.  
  2092. tag_suffix_e()
  2093. {
  2094.     tag_suffix_c();
  2095. }
  2096.  
  2097. tag_suffix_cc()
  2098. {
  2099.     tag_suffix_c();
  2100. }
  2101.  
  2102. tag_suffix_cpp()
  2103. {
  2104.     tag_suffix_c();
  2105. }
  2106.  
  2107. #ifdef foo
  2108. /* rebuild the default character maps */
  2109. when_loading()
  2110. {
  2111. #define UCLC(up, low)   _def_char_class[low] = C_LOWER, \
  2112.                         _def_char_class[up] = C_UPPER, \
  2113.                         _def_srch_case_map[up] = low, \
  2114.                         _def_case_map[low] = up, \
  2115.                         _def_case_map[up] = low
  2116.  
  2117.     int i, j;
  2118.  
  2119.     for (i = 0; i < 256; i++)
  2120.         _def_case_map[i] = _def_srch_case_map[i] = i;
  2121.     for (i = 'A', j = 'a'; i <= 'Z'; i++, j++)
  2122.         UCLC(i, j);
  2123.     for (i = 131; i < 154; i++)
  2124.         _def_char_class[i] = C_LOWER;
  2125.     for (i = 160; i < 164; i++)
  2126.         _def_char_class[i] = C_LOWER;
  2127.     UCLC('Ç', 'ç');
  2128.     UCLC('Ä', 'ä');
  2129.     UCLC('Å', 'å');
  2130.     UCLC('É', 'é');
  2131.     UCLC('Æ', 'æ');
  2132.     UCLC('Ö', 'ö');
  2133.     UCLC('Ü', 'ü');
  2134.     UCLC('Ñ', 'ñ');
  2135. }
  2136. #endif
  2137.